/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package impresion;

import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.PdfWriter;
import emailSW.MailUtils;
import empresa.DatosEmpresa;
import gestion.Factura;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.persistence.Query;

/**
 *
 * @author rocio
 */
public abstract class Imprimir {
    protected Document documento;
    private Boolean a;
    private javax.persistence.EntityManager lpdPUEntityManager;
    
    protected abstract void copiar();
    protected abstract String getTit();
    protected abstract void setDescripcion() throws DocumentException, Exception;


    public void imprimir() throws DocumentException, IOException, Exception{
        lpdPUEntityManager = java.beans.Beans.isDesignTime() ? null : javax.persistence.Persistence.createEntityManagerFactory("lpdPU").createEntityManager();
        documento=new Document();
        String tit=getTit();
        try{
            PdfWriter.getInstance (documento, new FileOutputStream (tit));
        }catch(Exception e){
        }
        documento.open();
        Query q=lpdPUEntityManager.createQuery("SELECT d FROM DatosEmpresa d");
        DatosEmpresa datosEmpresa=(DatosEmpresa) q.getSingleResult();

        a = documento.add(new Paragraph("DATOS DE LA EMPRESA:\n NIF:"+datosEmpresa.getNif()));
        a = documento.add(new Paragraph(" Nombre:"+datosEmpresa.getNombreEmpresa()));

        a = documento.add(new Paragraph(" Direccion:"+datosEmpresa.getDireccion()+"                    CP: "+datosEmpresa.getCp()+"               Localidad: "+datosEmpresa.getLocalidad()));

        a = documento.add(new Paragraph(" Telefono:"+datosEmpresa.getTelefono()+"                Email: "+datosEmpresa.getEmail()+"\n--------------------------------------------------------------------------------------------------------------------------------"));
        setDescripcion();


        documento.close();

       copiar();


    }



}
